<template>
<!-- 分页 -->
  <div class="pagination-custom">
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :layout="layout"
      :page-sizes="pageSizes" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>

<script setup>
defineProps({
  total: {
    required: true,
    type: Number,
    default: 0
  },
  pageSizes: {
    type: Array,
    default () {
      return [10, 20, 30, 50]
    }
  },
  layout: {
    type: String,
    default: 'total, sizes, prev, pager, next, jumper'
  }
})

const emit = defineEmits(['pagination'])

const currentPage = defineModel('page', {
  type: Number,
  required: true,
  default: 1
})
const pageSize = defineModel('limit', {
  type: Number,
  required: true,
  default: 10
})

const handleSizeChange = (val) => {
  emit('pagination', { page: currentPage.value, limit: val })
}

const handleCurrentChange = (val) => {
  emit('pagination', { page: val, limit: pageSize.value })
}
</script>

<style lang="scss" scoped>
.pagination-custom {
  margin-top: 15px;
  display: flex;
  justify-content: end;
}
</style>
